import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
// 评论粘的
const SET_COMMENT_LIST = 'setCommentList';
const INCREMENT = 'increment';
const DECREMENT = 'decrement';

export default new Vuex.Store({
  state: {
    username: '',
    name: '',
    userKey: '',
    chapterData: {}, //小节数据
    CSdata: {}, //章节数据
    commentList: [], //评论列表
    id: 100, //评论的
    ExampleKey: null, //算例key
    isCheck: 1, //content中的isCheck
    ExampleData: [], //算例数据
    whichModule: 0, //0是课程学习模块，1是作业管理模块
  },
  mutations: {
    saveUserName(state, username) {
      state.username = username;
    },
    saveName(state, name) {
      state.name = name;
    },
    saveUserKey(state, userKey) {
      state.userKey = userKey;
    },
    savaChapterData(state, chapterData) {
      state.chapterData = chapterData;
    },
    saveCSdata(state, CSdata) {
      state.CSdata = CSdata;
    },
    saveExampleKey(state, ExampleKey) {
      state.ExampleKey = ExampleKey;
    },
    saveisCheck(state, isCheck) {
      state.isCheck = isCheck;
    },
    saveExampleData(state, ExampleData) {
      state.ExampleData = ExampleData;
    },
    saveWhichModule(state, whichModule) {
      state.whichModule = whichModule;
    },
    // 评论粘的
    [SET_COMMENT_LIST](state, commentList) {
      state.commentList = commentList;
    },
    [INCREMENT](state) {
      state.id += 1;
    },
  },
  actions: {
    saveUserName(context, username) {
      context.commit('saveUserName', username);
    },
    saveName(context, name) {
      context.commit('saveName', name);
    },
    saveUserKey(context, userKey) {
      context.commit('saveUserKey', userKey);
    },
    savaChapterData(context, chapterData) {
      context.commit('savaChapterData', chapterData);
    },
    saveCSdata(context, CSdata) {
      context.commit('saveCSdata', CSdata);
    },
    saveExampleKey(context, ExampleKey) {
      context.commit('saveExampleKey', ExampleKey);
    },
    saveisCheck(context, isCheck) {
      context.commit('saveisCheck', isCheck);
    },
    saveExampleData(context, ExampleData) {
      context.commit('saveExampleData', ExampleData);
    },
    saveWhichModule(context, whichModule) {
      context.commit('saveWhichModule', whichModule);
    },
  },
  modules: {},
});
